<template>
    <el-dialog
        v-model="dialogVisible"
        title="药品添加"
        width="500"
        height="600"
        :before-close="handleClose"
         @open="initForm" 
    >
    <!-- 引入表单 -->
    <el-form :inline="true" :model="formValue" class="demo-form-inline"  label-position="right">
        <el-row>
            <el-col :span="12">
                <el-form-item label="药品:">
                    <el-input v-model="formValue.medicineName" />
                </el-form-item>
            </el-col>
             <el-col :span="12">
                <el-form-item label="药的类别:">
                     <el-select v-model="formValue.category" style="width: 170px;">
                        <el-option label="处方药" value=" 0" />
                        <el-option label="非处方药" value=" 1" />
                     </el-select>
                </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="12">
                <el-form-item label="规格:">
                    <el-input v-model="formValue.specification"/>
                </el-form-item>
            </el-col>
             <el-col :span="12">
                 <el-form-item label="单位:">
                    <el-input v-model="formValue.unit"/>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
                 <el-form-item label="售价:">
                    <el-input type="number" v-model="formValue.purchasePrice"/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="生产商:">
                    <el-input v-model="formValue.manufacturer"/>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
                <el-form-item label="最小库存:">
                    <el-input type="number" v-model="formValue.minStock"/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="最大库存:">
                    <el-input type="number" v-model="formValue.maxStock"/>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
                <el-form-item label="创建人:">
                <el-input disabled v-model="formValue.createBy"/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="创建时间:">
                    <el-date-picker
                        v-model="formValue.createTime"
                        type="date"
                        disabled
                        placeholder="时间"
                        style="width: 100%"
                        format="YYYY-MM-DD"
                    />
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>
    <template #footer>
    <div class="dialog-footer">
        <el-button @click="cancelFun">取消</el-button>
        <el-button type="primary" @click="saveData">保存</el-button>
    </div>
    </template>
    </el-dialog>
</template>

<script>
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import { reactive } from 'vue';
import { userAuthStore } from '../../store/authStore'
var useAuth = userAuthStore();
export default {
    // 父组件传递的初始数据通过props获取
    props: {
        
    },

    data() {
        return {
            formValue: {},
            dialogVisible: false,
            defaultTime : ''
        };
    },

    computed: {
       // new Date(2000, 1, 1, 0, 0, 0),
    },

    methods: {
        //取消
        cancelFun() {
            debugger
            this.$emit('cancel');//子组件给父组件传值
            this.dialogVisible = false;
        },

        //保存
        saveData() {
            debugger
            var formData = reactive(this.formValue);
            this.$emit('save',formData);//子组件给父组件传值
            this.dialogVisible = false;
        },

        //对数据进行初始化
        initForm() {
            debugger
            var date = new Date();
            var c_date = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getUTCDate();
            this.formValue.createBy = useAuth.user.userName;
            this.formValue.createTime = c_date;
        }

    },
};
</script>
<style>

</style>